package edu.washington.cs.workflow.matching;

import java.util.Map;

import com.ibm.wala.ipa.callgraph.CGNode;

import edu.washington.cs.workflow.analysis.AnalysisBuilder;
import edu.washington.cs.workflow.analysis.AnalysisBuilder.CG;
import edu.washington.cs.workflow.analysis.AnalysisBuilder.UIFramework;
import edu.washington.cs.workflow.util.Utils;
import junit.framework.TestCase;

//1 OK
public class TestMatchingCrossword extends TestCase {
	
	public void testFindMethodInCrossword() {
		String[] pkgs = new String[]{"crosswordsage"};
		
		String oldDir = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\crossword-0.3.jar";
		String oldMain = "Lcrosswordsage/MainScreen";
		AnalysisBuilder oldBuilder = new AnalysisBuilder(oldDir, oldMain, pkgs);
//		oldBuilder.setExclusionFile("Java60SwingExclusion.txt");
		oldBuilder.setCGType(CG.RTA);
		oldBuilder.setUIFramework(UIFramework.SWING);
		oldBuilder.buildAnalysis();
		
		String newDir = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\crossword-0.3.5.jar";
		String newMain = "Lcrosswordsage/MainScreen";
		AnalysisBuilder newBuilder = new AnalysisBuilder(newDir, newMain, pkgs);
		newBuilder.setCGType(CG.RTA);
		newBuilder.setUIFramework(UIFramework.SWING);
		newBuilder.buildAnalysis();
		
		String signature = "crosswordsage.MainScreen.showCrosswordBuilder()V";
		CGNode oldNode = oldBuilder.findCGNodeBySignature(signature);
		Utils.checkNotNull(oldNode);
		
		ExecutionTraceMatcher matcher = new ExecutionTraceMatcher(oldBuilder, newBuilder);
		CGNode mappedNode = matcher.findMatchedMethodByName(oldNode);
		Utils.checkNotNull(mappedNode);
		
		CGNode couterpart = matcher.findCounterpart(oldNode);
		Utils.checkNotNull(couterpart);
	}
	
}